import com.lbi.core.helper.Attach;
import com.lbi.framework.mvc.collection.Collection;
import com.lbi.framework.mvc.view.ViewBase;

import example.app.models.Person;
import example.app.views.people.PersonThumbnailView;

import flash.geom.Point;

/**
 * @author michaelforrest
 */
 // Note the name of the class. Singular vs plural is an important
 // distinction when naming things and can be an easy way
 // to enhance the readability of your code
class example.app.views.people.PeopleMenuView extends ViewBase {
	// model
	private var people : Collection;
	
	// layout constants
	private static var THUMBNAIL_SPACING : Number = 180;
	
	// Again - created with the FDT template
	public static function create ( $parent : MovieClip, $depth : Number ) : PeopleMenuView
	{
		return Attach.MovieClipClass($parent,PeopleMenuView, $depth);     
	}
	function PeopleMenuView() {
		super();
		people = Person.people;
		for (var i : Number = 0; i < people.length; i++) {
			var person:Person = people[i];
			addThumbnailForPerson(person, i);
		}
		people.registerEvents(this,[Collection.CHANGED],"PersonThumbnailView");
	}
	private function addThumbnailForPerson(person : Person, index : Number) : Void {
		var thumb : PersonThumbnailView = 
				PersonThumbnailView.create(person,this,getNextHighestDepth());
		thumb._x = index * THUMBNAIL_SPACING;
	}
	private function respondToChanged () : Void {
		var new_x : Number = Stage.width/2 - people.getCurrentIndex() * THUMBNAIL_SPACING;
		animator.change(POSITION).setFrames(25);
		animator.setPosition( new Point(new_x, _y));
	}
}